﻿namespace Specifications.Testability
{
    using Extensions;
    using NUnit.Framework;
    using NUnit.Framework.SyntaxHelpers;
    using Sample;

    /// <summary>
    /// This will eventually be moved into Caliburn
    /// </summary>
    [TestFixture]
    public class When_testing_change_notification_against_all_properties_on_a_class
    {
        [Test]
        [ExpectedException(typeof (AssertionException))]
        public void a_notification_with_the_incorrect_property_name_will_fail()
        {
            var sut = new NotificationWithWrongName();

            sut.AssertThatAllProperties().RaiseChangeNotifcation();
        }

        [Test]
        public void by_default_reference_type_properties_will_be_set_to_null()
        {
            var sut = new PropertyWithReferenceType();
            sut.AssertThatAllProperties().RaiseChangeNotifcation();

            Assert.That(sut.SomeField, Is.Null);
        }

        [Test]
        [ExpectedException(typeof (AssertionException))]
        public void if_the_class_has_no_eligible_properties_the_assertion_will_fail()
        {
            var sut = new NoNotificationNecessary();

            sut.AssertThatAllProperties().RaiseChangeNotifcation();
        }

        [Test]
        public void some_properties_can_be_ignored()
        {
            var sut = new PartialNotification();
            sut.AssertThatAllProperties()
                .Ignoring(() => sut.NoNotification).RaiseChangeNotifcation();
        }

        [Test]
        public void specific_values_can_be_set_on_individual_properties()
        {
            var sut = new NotificationOnAllProperties();

            sut.AssertThatAllProperties()
                .SetValue(() => sut.String, "some_string").RaiseChangeNotifcation();

            Assert.That(sut.String, Is.EqualTo("some_string"));
        }

        [Test]
        public void the_assertion_will_pass_if_notification_is_correct()
        {
            var sut = new NotificationOnAllProperties();

            sut.AssertThatAllProperties().RaiseChangeNotifcation();
        }
    }
}